<?php
class UserAdmin extends Module
{	
	static  function permission(){
		return array(
						'user_add'		=>'Thêm User',
						'user_edit'		=>'Sửa thông tin User',
						'user_view'		=>'Xem thông tin User',
						'user_delete'	=>'Xóa User',
						);	
	}
	
	function UserAdmin($row)
	{
		Module::Module($row);

		CGlobal::$website_title = "Quản lý thành viên";
		
		$user_id = (int)Url::get("user_id",0);
		if(User::is_login()&&User::is_root()){
            if(User::have_permit(array_keys($this->permission())))
            {
                switch(Url::get("cmd"))
                {
                    case 'edit':
                        require_once 'forms/EditUser.php';
                        $this->add_form(new EditUserForm);
                        break;

                    case 'add':
                        require_once 'forms/AddUser.php';
                        $this->add_form(new AddUserForm);
                        break;

                    case "del_cache":
                        if($user_id){
                            User::getUser($user_id,0,1);
                        }

                        Url::redirect_url(Url::build_all(array("cmd","user_id")));

                        break;

                    case "active":
                        if($user_id)
                        {
                            if(User::have_permit('user_edit'))
                            {
                                DB::update("user",array("is_active" => 1),"id = $user_id");
                                DB::delete("user_active","user_id=$user_id");
                                User::getUser($user_id,1);
                            }
                        }
                        Url::redirect_url(Url::build_all(array("cmd","user_id")));
                        break;
                    case "un_active":
                        if($user_id)
                        {
                            if(User::have_permit('user_edit'))
                            {
                                DB::update("user",array("is_active" => 2),"id = $user_id");
                                User::getUser($user_id,1);
                            }
                        }

                        Url::redirect_url(Url::build_all(array("cmd","user_id")));
                        break;
                    default:
                        require_once "forms/UserAdmin.php";
                        $this->add_form(new ListUserAdminForm());
                        break;
                }
            }
            else
            {
                Url::redirect("sign_in");
            }
        }else{
            Url::access_denied();
        }

	}
}
?>
